package Management;

import javax.swing.Box;
import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JFrame;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import java.awt.event.*;
import java.awt.*;

public class MainWindow extends JFrame implements ActionListener {
     
 JDesktopPane desktop;

    public MainWindow() {
     
        super("Company Management");
            
        //Make the big window be indented 20 pixels from each edge
        //of the screen.
         int inset = 20;
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(0, 0, screenSize.width, screenSize.height - inset*2);

        //Set up the GUI.
        desktop = new JDesktopPane(); //a specialized layered pane
         //createFrame(); //create first "window"
        setContentPane(desktop);
        setJMenuBar(createMenuBar());

        //Make dragging a little faster but perhaps uglier.
        desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
     }

    protected JMenuBar createMenuBar() {
        JMenuBar menuBar = new JMenuBar();

        //Set up the file menu.
        JMenu menu = new JMenu(" File ");
        menu.setMnemonic(KeyEvent.VK_F);
        menuBar.add(menu);
        
        //Set up the first menu item.
        JMenuItem menuItem = new JMenuItem("Quit");
        menuItem.setMnemonic(KeyEvent.VK_Q);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK));
        menuItem.setActionCommand("Quit");
        menuItem.addActionListener(this);
        menu.add(menuItem);

        JMenu Pmenu = new JMenu(" Profile ");
        //menu.setMnemonic(KeyEvent.VK_P);
        menuBar.add(Pmenu);
        
        //Set up the first menu item.
        JMenuItem PmenuItem = new JMenuItem("New Profile");
        PmenuItem.setMnemonic(KeyEvent.VK_N);
        PmenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_N, ActionEvent.ALT_MASK));
        PmenuItem.setActionCommand("New Profile");
        PmenuItem.addActionListener(this);
        Pmenu.add(PmenuItem);
        
        //Set up the Profile Manager
        JMenuItem PmmenuItem = new JMenuItem("Profile Manager");
        PmmenuItem.setMnemonic(KeyEvent.VK_P);
        PmmenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_P, ActionEvent.ALT_MASK));
        PmmenuItem.setActionCommand("Profile Manager");
        PmmenuItem.addActionListener(this);
        Pmenu.add(PmmenuItem);
        
        Pmenu.addSeparator();
        
/*      JMenuItem MmenuItem = new JMenuItem("Master Table");
        menuItem.setMnemonic(KeyEvent.VK_N);
        MmenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_N, ActionEvent.ALT_MASK));
        MmenuItem.setActionCommand("new");
        MmenuItem.addActionListener(this);
        Pmenu.add(MmenuItem);    
*/        
        JMenu submenu = new JMenu("Master Table");
        submenu.setMnemonic(KeyEvent.VK_S);
        
        Pmenu.add(submenu);

        menuItem = new JMenuItem("Class Entry/ Maintenance");
        menuItem.addActionListener(this); 
        submenu.add(menuItem);
        
        menuItem = new JMenuItem("Season Entry/ Maintenance");
        menuItem.addActionListener(this); 
        submenu.add(menuItem);       
        
        menuItem = new JMenuItem("Future Entry/ Maintenance");
        submenu.add(menuItem);   
        
        submenu.addSeparator();
        
        menuItem = new JMenuItem("Teacher/Assistant Entry/ Maintenance");      
        submenu.add(menuItem);
        
        JMenu AllocationsmenuItem = new JMenu(" Allocation ");
        menu.setMnemonic(KeyEvent.VK_A);
        menuBar.add(AllocationsmenuItem);        
        
        JMenu GrademenuItem = new JMenu("Grade");
        menu.setMnemonic(KeyEvent.VK_G);
        menuBar.add(GrademenuItem);
        
        JMenuItem grademanagermenuitem = new JMenuItem("Grade Manager");
        grademanagermenuitem.setActionCommand("Grade Manager");
        grademanagermenuitem.addActionListener(this);
        GrademenuItem.add(grademanagermenuitem);
        
        
/*      JMenuItem firstgrademenuItem = new JMenuItem("First Grade");
        firstgrademenuItem.setActionCommand("First Grade");
        firstgrademenuItem.addActionListener(this);
        GrademenuItem.add(firstgrademenuItem);
        
        JMenuItem secondgrademenuItem = new JMenuItem("Second Grade");
        secondgrademenuItem.setActionCommand("Second Grade");
        secondgrademenuItem.addActionListener(this);
        GrademenuItem.add(secondgrademenuItem);
        
        JMenuItem thirdgrademenuItem = new JMenuItem("Third Grade");
        thirdgrademenuItem.setActionCommand("Third Grade");
        thirdgrademenuItem.addActionListener(this);
        GrademenuItem.add(thirdgrademenuItem);
        
        JMenuItem fourthgrademenuItem = new JMenuItem("Fourth Grade");
        fourthgrademenuItem.setActionCommand("Fourth Grade");
        fourthgrademenuItem.addActionListener(this);
        GrademenuItem.add(fourthgrademenuItem);
        
        JMenuItem fifthgrademenuItem = new JMenuItem("Fifth Grade");
        fifthgrademenuItem.setActionCommand("Fifth Grade");
        fifthgrademenuItem.addActionListener(this);
        GrademenuItem.add(fifthgrademenuItem);
        
        JMenuItem sixgrademenuItem = new JMenuItem("Six Grade");
        sixgrademenuItem.setActionCommand("Six Grade");
        sixgrademenuItem.addActionListener(this);
        GrademenuItem.add(sixgrademenuItem);

        JMenuItem seventhgrademenuItem = new JMenuItem("Seventh Grade");
        seventhgrademenuItem.setActionCommand("Six Grade");
        seventhgrademenuItem.addActionListener(this);
        GrademenuItem.add(seventhgrademenuItem);
*/        
        GrademenuItem.addSeparator();
        
        JMenu gradesubmenu = new JMenu("Reports");
        GrademenuItem.add(gradesubmenu);
        
        menuItem = new JMenuItem("Reports by Class");
        menuItem.addActionListener(this); 
        gradesubmenu.add(menuItem);   
        
        menuItem = new JMenuItem("Reports by Grade");
        menuItem.addActionListener(this); 
        gradesubmenu.add(menuItem);
        
        menuItem = new JMenuItem("Reports by Class and Grade");
        menuItem.addActionListener(this); 
        gradesubmenu.add(menuItem);
        
        JMenu ARmenuItem = new JMenu(" A/R ");
        menu.setMnemonic(KeyEvent.VK_F);
        menuBar.add(ARmenuItem);
        
        JMenu APmenuItem = new JMenu(" A/P ");
        menu.setMnemonic(KeyEvent.VK_F);
        menuBar.add(APmenuItem);
        
        JMenu HelpmenuItem = new JMenu ("Help");
        menu.setMnemonic(KeyEvent.VK_H);
        menuBar.add(HelpmenuItem);
        

        menuBar.add(Box.createHorizontalGlue()); // Create the space between the menu bar
        
        JMenu Amenu = new JMenu("Admin");
        menu.setMnemonic(KeyEvent.VK_A);
        menuBar.add(Amenu);
        
        JMenuItem CmenuItem = new JMenuItem("Change Division");
        CmenuItem.setMnemonic(KeyEvent.VK_D);
        //menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK));
        CmenuItem.setActionCommand("Change Division");
        CmenuItem.addActionListener(this);
        Amenu.add(CmenuItem);
        
        Amenu.addSeparator();
        
        JMenuItem LEMmenuItem = new JMenuItem("Location Entry/ Maintenance");
        LEMmenuItem.setMnemonic(KeyEvent.VK_C);
        //menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK));
        LEMmenuItem.setActionCommand("Class Entry/Maintenance");
        LEMmenuItem.addActionListener(this);
        Amenu.add(LEMmenuItem);
        
        Amenu.addSeparator();
        
        return menuBar;
    }

    //React to menu selections.
    public void actionPerformed(ActionEvent e) {
    	if ("Quit".equals(e.getActionCommand())) { // sub menu season entry
    		System.exit(0);
        }
    	if ("New Profile".equals(e.getActionCommand())) {
        	createFrame();
        
        }
    	if ("Profile Manager".equals(e.getActionCommand())) {
        	createFrame();
        
        } 
        if ("Season Entry/ Maintenance".equals(e.getActionCommand())) { // sub menu season entry
            new SeasonManager().main(null);       
        }
        if ("Change Division".equals(e.getActionCommand())) { // sub menu season entry
            new DivisionFrame();
            dispose();
        }
        
        else { //quit
           // quit();
         }
    }

    //Create a new internal frame.
    protected void createFrame() {
        ProfileManager frame = new ProfileManager();
        
        frame.setVisible(true); //necessary as of 1.3
         
        desktop.add(frame);
        try {
            frame.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        	
        }
    }

    //Quit the application.
    protected void quit() {
         System.exit(0);
    }

    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
      
     
        //Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);  
        //UIManager.put("swing.boldMetal", Boolean.TRUE); 
        try {
             UIManager.setLookAndFeel(
                UIManager.getSystemLookAndFeelClassName());
            }
        catch (Exception e) {}
        
        //Create and set up the window.
        MainWindow frame = new MainWindow();
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Display the window.
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
         //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
     }
}